package com.zw.chat.domain;

import com.zw.chat.common.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

/**
 * @author by: zyl
 * @ClassName: ChatSession
 * @Description: 聊天会话
 * @Date: 2024/12/5 9:54
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Document(collection = "chat_session")
public class ChatSession extends BaseEntity {

    /* 会话标题 */
    private String topic;

    /* 聊天数 和 token数 */
    private Statistic statistic;

    @Transient
    private List<ChatMessage> messages;

    /* 用户 */
    @DBRef
    private User creatAt;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Statistic {
        private Integer charCount;
        private Integer tokenCount;

        public Statistic plusChar(Integer charCount) {
            this.charCount += charCount;
            return this;
        }

        public Statistic plusToken(Integer tokenCount) {
            this.tokenCount += tokenCount;
            return this;
        }
    }

}
